package com.hugang.designmode.singleton;

/**
 * 单例模式：饿汉式
 *
 * @author hg
 * @date 2020/6/12 10:42
 */
public class SingletonHungryTypeTest {

    public static void main(String[] args) {
        Bank bank1 = Bank.getInstance();
        Bank bank2 = Bank.getInstance();
        System.out.println(bank1 == bank2);

    }

}

class Bank {

    /**
     * 1、私有化构造器
     */
    private Bank() {

    }

    /**
     * 2、声明静态实例
     */
    private static Bank instance = new Bank();


    /**
     * 3、提供公共的获取实例的方法
     *
     * @return instance
     */
    public static Bank getInstance() {
        return instance;
    }
}
